package com.wefiesta.app;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class RealMainActivity extends Fragment implements OnItemClickListener {
	
	ListView listView;
	View vw_layout;
	
	String data[] = {"Events","Organize","Friends"};
	
	private String dataMainTitle[] = {"Beach party at Sunset boulevard, New York", "Test Party1", "Test Party2"};
	private Integer iMainTitleCount = 0;
	
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		
	}
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

		if (container == null) {
			return null;
		}
		vw_layout = inflater.inflate(R.layout.activity_realmain, container, false);
		ImageView btnMainRight = (ImageView) vw_layout.findViewById(R.id.main_right);
		btnMainRight.setOnClickListener(new OnClickListener() {
            public void onClick(final View v) {
            	Log.d("Log Cat", "Main Light Button :" + iMainTitleCount);
    			
    			iMainTitleCount++;
    			if(iMainTitleCount >= dataMainTitle.length-1) iMainTitleCount = dataMainTitle.length-1;
    			
    			
    			// Event Title
    			TextView tvTitle = (TextView)vw_layout.findViewById(R.id.tv_event_title);
    			tvTitle.setText(dataMainTitle[iMainTitleCount%3]);
    						
    			// Event Image
    			ImageView ivEventImg = (ImageView)vw_layout.findViewById(R.id.main_event_img);
    			String mDrawableName = "mainphoto" + iMainTitleCount;
    			int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName());
    			ivEventImg.setImageResource(resID);
            }
        });
		
		ImageView btnMainLeft = (ImageView)vw_layout.findViewById(R.id.main_left);
		btnMainLeft.setOnClickListener(new OnClickListener() {
            public void onClick(final View v) {
            	Log.d("Log Cat", "Main Left Button :" + iMainTitleCount);
    			
    			iMainTitleCount--;
    			if(iMainTitleCount <= 0) iMainTitleCount = 0;
    				
    			TextView tvTitle = (TextView)vw_layout.findViewById(R.id.tv_event_title);
    			tvTitle.setText(dataMainTitle[iMainTitleCount%3]);
    			
    			// Event Image
    			ImageView ivEventImg = (ImageView)vw_layout.findViewById(R.id.main_event_img);
    			String mDrawableName = "mainphoto" + iMainTitleCount;
    			int resID = getResources().getIdentifier(mDrawableName , "drawable", getPackageName());
    			ivEventImg.setImageResource(resID);
            }
        });
		
		return vw_layout;
	}
	
	private String getPackageName(){
		return "com.wefiesta.app";
	}
}
